home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-07 | 8.5 KB | 349 lines | [TEXT/ALFA] |
-
- ################################################################################
- # Shell routines.
- ################################################################################
-
-
- proc setShellMode {} {
- setTclMode
- changeMode "Csh"
- insertMenu "Tcl"
- }
-
- proc initShell {} {
- insertText "Welcome to Alpha's Tcl shell."
- insertText -w [lindex [winNames] 0] [shellPrompt]
- }
-
- # Return the prompt. We want the window name because some of the commands
- # we evaluate (such as 'edit') open a new window, and we want the insertion
- # to be done in the shell window.
- proc shellPrompt {} {
- regexp "(\[^:\]*):$" [pwd] crDum crDir
- return "\r$crDir> "
- }
-
-
- # Called at all carriage returns.
- proc carriageReturn {} {
- global mode
- global indentOnCR
- set indentString ""
- deleteText [getPos] [selEnd]
- if {$indentOnCR} {
- set pos [getPos]
- set text [getText [lineStart $pos] $pos]
- for {set i 0; set len [string length $text]} {$i <= $len} {incr i} {
- set c [string index $text $i]
- if {($c != "\t") && ($c != "\ ")} {
- set indentString [string range $text 0 [expr $i-1]]
- break
- }
- }
- }
- insertText "\r" $indentString
- }
-
-
- proc tclCarriageReturn {} {
- global mode
- global _text
- global _returnText
- set pos [getPos]
- set ind [string first ">" [getText [lineStart $pos] $pos]]
- if {$ind < 0} {
- carriageReturn
- return
- }
- set lStart [expr [lineStart $pos]+$ind+2]
- endOfLine
- set _text [getText $lStart [getPos]]
- set fileName [lindex [winNames] 0]
- if {[getPos] != [maxPos]} {
- goto [maxPos]
- insertText -w $fileName $_text
- }
- if {[string first "Toolserver" $fileName] != -1} {
- if {![catch {dosc -n ToolServer -s $_text} _returnText]} {
- insertText "\r" $_returnText
- } else {
- insertText "\r"
- }
- mpwPrompt
- } else {
- uplevel #0 {catch $_text _returnText}
- if {[string length $_returnText]} {
- insertText -w $fileName "\r" $_returnText [shellPrompt]
- } else {
- insertText -w $fileName [shellPrompt]
- }
- }
- unset _text
- unset _returnText
- }
- bind '\r' carriageReturn
- bind '\r' tclCarriageReturn "Csh"
- bind '\r' tclCarriageReturn "MPW"
-
- proc startMPW {} {
- global toolserverPath
-
- if {![string length [checkRunning ToolServer MPSX toolserverPath]]} return
-
- insertText "Welcome to Alpha's MPW shell (using ToolServer via AppleEvents)."
- bind '\r' tclCarriageReturn "MPW"
- carriageReturn
- mpwPrompt
- }
- proc mpwPrompt {} {
- insertText "mpw> "
- }
-
- proc setMPWMode {} {
- changeMode "MPW"
- }
-
- # tclCarriageReturn
-
-
-
- #=============================================================================
- # Shell Aliases
- #=============================================================================
-
-
- proc l {args} {
- eval [concat "ls -CF" $args]}
-
- proc ll {args} {
- eval [concat "ls -l" $args]}
-
-
- proc wc {args} {
- set totChars 0
- set totLines 0
- set totWords 0
- set args [glob -nocomplain $args]
- foreach file $args {
- set id [open $file]
- set chars [string length [set text [read $id]]]
- set lines [llength [split $text "\n"]]
- set words [llength [split $text]]
- insertText [format "\r%8d%8d%8d $file" $lines $words $chars]
- set totChars [expr $totChars+$chars]
- set totWords [expr $totWords+$words]
- set totLines [expr $totLines+$lines]
- close $id
- }
- if {[llength $args] > 1} {
- insertText [format "\r%8d%8d%8d total" $totLines $totWords $totChars]
- }
- }
-
- ###########################################################################
- # better-cp-mv.tcl -- modification of your routines, by Mark Nagata
- # for Alpha 5.72, 1/04/94
- ###########################################################################
- proc cp args {
- if {[set len [llength $args]] < 2} {
- error "usage: cp <file1> <file2>\r cp <file1> .... <dir>"
- }
- set len [expr $len-1]
- if {![regexp {.*[^:]} [lindex $args $len] dir]} {
- set dir [string range [lindex $args $len] 1 end]
- }
- if {![regexp {:} $dir] && $dir != ""} {
- set dir [concat :$dir]}
- set args [lreplace $args $len $len]
- set files {}
- foreach arg $args {
- append files " " [glob $arg]
- }
- set report ""
- if {[llength $files] == 1} {
- set f [lindex $files 0]
- if {[file exists $dir]} {
- set targ $dir:[file tail $f]
- append report $f\ ->\ $targ \r
- copyFile $f $targ
- } else {
- append report $f\ ->\ $dir \r
- copyFile $f $dir
- }
- } else {
- foreach f $files {
- set targ $dir:[file tail $f]
- append report $f\ ->\ $targ \r
- if {[catch {copyFile $f $targ} that]} {
- alertnote "Error copying '$f' -> '$targ': $that"
- }
- }
- }
- echo $report
- }
-
- proc mv args {
- if {[set len [llength $args]] < 2} {
- error "usage: mv <file1> <file2>\r mv <file1> .... <dir>"
- }
- set len [expr $len-1]
- if {![regexp {.*[^:]} [lindex $args $len] dir]} {
- set dir [string range [lindex $args $len] 1 end]
- }
- if {![regexp {:} $dir] && $dir != ""} {
- set dir [concat :$dir]}
- set args [lreplace $args $len $len]
- set files {}
- foreach arg $args {
- append files " " [glob $arg]
- }
- set report ""
- if {[llength $files] == 1} {
- set f [lindex $files 0]
- if {[file exists $dir]} {
- set targ $dir:[file tail $f]
- append report $f\ >->\ $targ \r
- moveFile $f $targ
- } else {
- append report $f\ >->\ $dir \r
- moveFile $f $dir
- }
- } else {
- foreach f $files {
- set targ $dir:[file tail $f]
- append report $f\ >->\ $targ \r
- if {[catch {moveFile $f $targ} that]} {
- alertnote "Error moving '$f' -> '$targ': $that"
- }
- }
- }
- echo $report
- }
-
-
- proc rm args {
- set files {}
- foreach arg $args {
- append files " " [glob $arg]
- }
- foreach f $files {
- removeFile $f
- }
- }
-
-
- proc getTypeCreator {f} {
- set l [ls -l $f]
- set len [llength $l]
- list [lindex $l [expr $len-4]] [lindex $l [expr $len-3]]
- }
-
-
- #================================================================================
-
-
- proc tclFileCompletion {} {
- set silly "*"
- set pos [getPos]
- set res [search -f 0 -i 0 -m 0 -r 1 -n {["\{ \t\r]} [expr $pos - 1]]
- if {[string length $res]} {
- set from [lindex $res 1]
- if {$from < $pos} {
- set pd [pwd]
- set text [getText $from $pos]
- if {[string index $text 0] == ":"} {
- set pd [string trimright $pd ":"]
- }
- if {[catch {glob $pd$text$silly} globbed]} {
- set globbed [glob $text$silly]
- set pd ""
- }
- if {[llength $globbed] == 1} {
- set len [string length $pd$text]
- insertText [string range [lindex $globbed 0] $len end]
- } elseif {[llength $globbed] != 0} {
- set globbed [lsort $globbed]
- set one [lindex $globbed 0]
- set two [lindex $globbed end]
-
- set len [string length $pd$text]
- set one [string range $one $len end]
- set two [string range $two $len end]
-
- set elen [string length $one]
- if {[string length $two] < $elen} {
- set elen [string length $two]
- }
- set len 0
- set str ""
- while {($len < $elen) && ([string match $str[string index $one $len]$silly $two])} {
- append str [string index $one $len]
- incr len
- }
-
- if {!$len} {
- set elen [string length $pd]
- foreach g $globbed {
- lappend short [string range $g $elen end]
- }
- set blah [getText [lineStart [getPos]] [getPos]]
- insertText "\r" $short "\r" $blah
- } else {
- insertText $str
- }
- }
- }
- }
- }
-
-
-
- #================================================================================
- # To prevent ambiguity, 'from' is assumed to be a complete pathname, ending
- # in a directory name. If it doesn't end w/ a colon, one is added. 'to' is
- # assumed to be the parent directory of the top directory we are creating.
- #================================================================================
- proc cpdir {from to} {
- set cwd [pwd]
- if {[string match ":*" $from] || [string match ":*" $to] ||
- ![file exists $from] || ![file exists $to]} {
- error "'cpdir' args must be complete pathnames of existing folders."
- }
- if {![string match "*:" $from]} {append from ":"}
- if {![string match "*:" $to]} {append to ":"}
-
- if {![file isdir $from] || ![file isdir $to]} {
- exit 1
- }
-
- cphier $from $to
- cd $cwd
- }
-
- proc cphier {from to} {
- set dir [file tail [string trimright $from ":"]]
- cd $to
- mkdir "$dir"
- foreach f [glob "$from*"] {
- if {[file isdir $f]} {
- cphier "$f:" "$to$dir:"
- } else {
- cp $f $to$dir:
- }
- }
- }
-
-
- if {![string length [info commands oldMkdir]]} {
- rename mkdir oldMkdir
- rename rmdir oldRmdir
- }
-
- proc mkdir {dir} {
- oldMkdir [list $dir]
- }
-
- proc rmdir {dir} {
- oldRmdir [list $dir]
- }
-